package cate.common.table.activity.skindraw.sheet;
import cate.common.table.ESheet;
import cate.common.table.activity.skindraw.row.SkinDrawPoolRow;
import cate.common.util.random.RWList;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class SkinDrawPoolSheet extends ESheet<SkinDrawPoolRow>{
    @Override
    public String getSheetName() {
        return "抽奖奖励池";
    }

    public SkinDrawPoolRow randomPool(int group, int skinId, double weight, Map<Integer,Double> cheatIds){
        List<SkinDrawPoolRow> rows = getList().stream().
                filter(row -> (row.group == group && !cheatIds.containsKey(row.skinId))).collect(Collectors.toList());
        if (rows.isEmpty()) {
            return null;
        }
        if (skinId != 0) {
            for (SkinDrawPoolRow row : rows) {
                String[] split = row.reward.split(":");
                int chooseId = Integer.parseInt(split[1]);
                if (chooseId == skinId) {
                    row.weight = weight;
                }
            }
        }
        RWList<SkinDrawPoolRow> rwList = new RWList<>();
        rwList.addAll(rows);
        SkinDrawPoolRow rowRandom = rwList.setup().get();

        if (skinId != 0) {
            for (SkinDrawPoolRow row : rows) {
                String[] split = row.reward.split(":");
                int chooseId = Integer.parseInt(split[1]);
                if (chooseId == skinId) {
                    row.weight = 0;
                }
            }
        }
        return rowRandom;
    }
}
